<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--#include file="DataLoad.asp"-->
<%Call CheckAdmin2()%>

<html>
<head>
<title><%=GuildName%> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<%=StylePath%>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<%=StylePath%>/styleplus.js"></script>
<style type="text/css" media="all">
</style>

</head>

<body>
<div class="header">
<!--#include file="menu.asp"-->
</div>
<div class="main">
<div>
<b>注意:请在生成数据文件前确认,已经通过生成所有DKP列表完成了数据缓存更新.</b>
</div>
<table class="outframe">
	<tr>
		<th colspan="2">输出DKP数据到MerDKP插件</th>
	</tr>
	</tr>
	<tr><td></td><td><a href='?action=MerDKP2' class='abtn'>生成MerDKP 2.0 用数据文件</a></td></tr>
</table>


<table class="outframe">
	<tr>
		<th colspan="2">输出用于DKPtable插件的DKP数据</th>
	</tr>
	<tr class="coltitle"><td colspan="2">图形化的dkp数据查询插件,可同时支持多套dkp的查询 <a href="http://bbs.game.mop.com/viewthread.php?tid=1179228&extra=page%3D1" target="_blank">点击查看详细</a></td></tr>
	</tr>
	<tr><td>操作:</td><td><a href='?action=DKPtable'>生成文件 (Dkp_table1.15适用)</a></td></tr>
</table>

<table class="outframe interlace">
<tr>
	<th colspan="2">输出用于dkp_system插件的DKP数据</th>
</tr>
<tr class="coltitle"><td>分类</td><td>操作</td></tr>
<%
sql="select * from raid_class"
rs.open sql,conn,1,1
	for i = 1 to rs.recordcount
		response.write "<tr><td>"&rs("class_name")&"</td><td><a href='?action=dkpsystem&amp;id="&rs("id")&"'>生成文件</a></td></tr>"
	rs.movenext
	next
rs.close
%>
<tr class="coltitle"><td colspan="2">注意:在输出之前请现在点击生成DKP详表以更新到最新数据</td></tr>
</table>

<%
if request("action")="dkpsystem" then
end if

Select Case Request("action")
	Case "dkpsystem"
		Response.write "<div class='message'><h3>下载文件</h3><div>"
		call export_dkpsystem()
		Response.write "</div></div>"
	Case "MerDKP"
		Response.write "<div class='message'><h3>下载文件</h3><div>"
		call export_MerDKP()
		Response.write "</div></div>"
	Case "MerDKP136"
		Response.write "<div class='message'><h3>下载文件</h3><div>"
		call export_MerDKP136()
		Response.write "</div></div>"
	Case "MerDKP2"
		Response.write "<div class='message'><h3>下载文件</h3><div>"
		call export_MerDKP2()
		Response.write "</div></div>"
	Case "DKPtable"
		Response.write "<div class='message'><h3>下载文件</h3><div>"
		call export_DKPtable()
		Response.write "</div></div>"
	Case "DKPBackup"
		call dkpBackup()
End Select
%>
</div>
<div id="footer"><!--#include file="footer.asp"--></div>
</body>
</html>
</head>

<body>
<%
Sub  export_dkpsystem()
	if request("id")="" or not IsNumeric(request("id")) then exit sub
	dim dkpdata,total_players,total_items,total_points
	total_players=0
	total_items=0
	total_points=0
dkpdata=dkpdata&"--========================" &vbCrlf
dkpdata=dkpdata&"-- Created by FSDKP" &vbCrlf
dkpdata=dkpdata&"-- File Created at "&now() &vbCrlf
dkpdata=dkpdata&"-- Guild:"&GuildName &vbCrlf
dkpdata=dkpdata&"-- DKP分类:"&raidclassText(request("id")) &vbCrlf
dkpdata=dkpdata&"--========================" &vbCrlf


dkpdata=dkpdata&"DKP_ROLL_PLAYERS = {" &vbCrlf
sql="select * from player order by id desc"
rs.open sql,conn,1,1
	for i = 1 to rs.recordcount
		thisdkp=totaldkp(rs("id"),request("id"))
		dkpdata=dkpdata&"    ["""&rs("player_name")&"""] = {" &vbCrlf
		dkpdata=dkpdata&"          [""RaidPoints""] = "&thisdkp&"," &vbCrlf
		dkpdata=dkpdata&"          [""Class""] = """&rs("player_profession")&"""," &vbCrlf
		dkpdata=dkpdata&"    }," &vbCrlf
		total_players=total_players+1
		total_points=total_points+thisdkp
		rs.movenext
	next
rs.close
dkpdata=dkpdata&"}" &vbCrlf

dkpdata=dkpdata&"DKP_ROLL_UPDATE_INFO = {" &vbCrlf
dkpdata=dkpdata&"     [""date""] = """&now()&"""," &vbCrlf
dkpdata=dkpdata&"     [""process_dkp_ver""] = ""FSDKP 1.3.1""," &vbCrlf
dkpdata=dkpdata&"     [""total_players""] = "&total_players&"," &vbCrlf
dkpdata=dkpdata&"     [""total_items""] = "&total_items&"," &vbCrlf
dkpdata=dkpdata&"     [""total_points""] = "&total_points&"," &vbCrlf
dkpdata=dkpdata&"}" &vbCrlf



	call WriteFile("export/","sqlvars.lua.txt",dkpdata) 

end sub

Sub WriteFile(strFilepath,strFilename,strFileText) 
Set objStream = Server.CreateObject("ADODB.Stream")
    With objStream
    .Open
    .Charset = "utf-8"
    .Position = objStream.Size
    .WriteText=strFileText
    .SaveToFile server.mappath(strFilepath&strFilename),2 
    .Close
	End With
   response.write "已保存文件: <a href='"&strFilepath&strFilename&"'>"&strFilepath&strFilename&"</a> (右键点击""另存为""下载后请去掉.txt后缀)"
Set objStream = Nothing
end sub



Sub dkpBackup()
	'定义变量
	Dim XMLText
	Dim GuildName , GuildCreateDate ,GuildNote
	Dim Players , ArrLoot , ArrDKP
	Dim DICreateTime , DICreateBy , DIVersion

	'读取数据
	Sql="Select * from guild"
	rs.open sql,conn,1,1
		if rs.eof or rs.bof then
			Response.write "缺少公会信息"
			Response.End
		else
			GuildName = rs("guild_name")
			GuildCreateDate = rs("guild_createtime")
			GuildNote = rs("guild_sname")
		end if
	rs.close

	Sql="Select * From player order by player_name"
	rs.open sql,conn,1,1
		if rs.eof or rs.bof then
			Response.write "未找到成员"
			Response.End
		else
			Redim Players(rs.recordCount-1,7)
			for i = 0 to rs.recordCount-1
				Players(i,0) = rs("player_name")
				Players(i,1) = rs("player_profession")
				Players(i,2) = rs("player_tribe")
				Players(i,3) = rs("player_level")
				Players(i,4) = "" 'ExtraInfo
				Players(i,5) = "" 'Looted
				Sql="Select * from player_dkp where player_id="&rs("id")&" order by raid_class"&c
				rs2.open sql,conn,1,1
					if rs2.eof or rs2.bof then
						Players(i,6) = "" 'DKP
					else
						for j = 1 to rs2.recordcount
						Players(i,6) = Players(i,6)&","&rs2("raid_class")&","&rs2("player_dkp") 'Looted
						rs2.movenext
						next
					end if
				rs2.close
				Players(i,7) = ""
				rs.movenext
			next
		end if
	rs.close

	'按格式输出
	XMLText = XMLText& "<?xml version=""1.0"" encoding=""gb2312""?>" &vbCrlf
	XMLText = XMLText& "<Guild>" &vbCrlf
	XMLText = XMLText& "	<GuildInfo>" &vbCrlf
	XMLText = XMLText& "		<GuildName>"&GuildName&"</GuildName>" &vbCrlf
	XMLText = XMLText& "		<GuildCreateDate>"&GuildCreateDate&"</GuildCreateDate>" &vbCrlf
	XMLText = XMLText& "		<GuildNote><![CDATA["&GuildNote&"]]></GuildNote>" &vbCrlf
	XMLText = XMLText& "	</GuildInfo>" &vbCrlf
	XMLText = XMLText& "	<Players>" &vbCrlf
	for i = 0 to Ubound(Players,1)
		XMLText = XMLText& "	<Player>" &vbCrlf
		XMLText = XMLText& "		<Name>"&Players(i,0)&"</Name>" &vbCrlf
		XMLText = XMLText& "		<PlayerClass>"&Players(i,1)&"</PlayerClass>" &vbCrlf
		XMLText = XMLText& "		<Race>"&Players(i,2)&"</Race>" &vbCrlf
		XMLText = XMLText& "		<Level>"&Players(i,3)&"</Level>" &vbCrlf
		XMLText = XMLText& "		<ExtraInfo><![CDATA["&Players(i,4)&"]]></ExtraInfo>" &vbCrlf

		XMLText = XMLText& "		<Looted>" &vbCrlf
		if Instr(Players(i,5),",")>0 then
		ArrDKP=Split(Right(Players(i,5),Len(Players(i,5))-1),",")
		for j = 0 to Ubound(ArrDKP) step 2
			XMLText = XMLText& "			<Item>" &vbCrlf
			XMLText = XMLText& "				<ItemName>""</ItemName>" &vbCrlf
			XMLText = XMLText& "				<ItemNote><![CDATA[xxx]]></ItemNote>" &vbCrlf
			XMLText = XMLText& "			</Item>" &vbCrlf
		next
		end if
		XMLText = XMLText& "		</Looted>" &vbCrlf

		XMLText = XMLText& "		<DKP>" &vbCrlf
		if Instr(Players(i,6),",")>0 then
		ArrDKP=Split(Right(Players(i,6),Len(Players(i,6))-1),",")
		for k = 0 to Ubound(ArrDKP) step 2
			XMLText = XMLText& "			<DKPClass>" &vbCrlf
			XMLText = XMLText& "				<ClassName>"&ArrDKP(k)&"</ClassName>" &vbCrlf
			XMLText = XMLText& "				<DKPCount>"&ArrDKP(k+1)&"</DKPCount>" &vbCrlf
			XMLText = XMLText& "			</DKPClass>" &vbCrlf
		next
		end if
		XMLText = XMLText& "		</DKP>" &vbCrlf

		XMLText = XMLText& "	</Player>" &vbCrlf
	next
	XMLText = XMLText& "	</Players>" &vbCrlf
	XMLText = XMLText& "	<DataInfo>" &vbCrlf
	XMLText = XMLText& "		<CreateTime>"&Now()&"</CreateTime>" &vbCrlf
	XMLText = XMLText& "		<CreateBy>FSDKP 1.3.0</CreateBy>" &vbCrlf
	XMLText = XMLText& "		<Version>1.0</Version>" &vbCrlf
	XMLText = XMLText& "	</DataInfo>" &vbCrlf
	XMLText = XMLText& "</Guild>"

	Response.write "<textarea name='' rows='15' cols='150'>"&XMLText&"</textarea>"
End Sub



function totaldkp(pid,c)
	sql="select * from player_dkp where player_id="&pid&" and raid_class="&c
	rs2.open sql,conn,1,1
		if rs2.eof or rs2.bof then
		SHowerror("数据未暂存,可能有新加入的成员没有获得在所有DKP类中的分数,请尝试生成全部DKP分类后再导出.")
		Response.end
		else
		totaldkp=rs2("player_dkp")
		end if
	rs2.close
end function




Sub  export_DKPtable()
	Dim ArrClass , membercount
	dim dkpdata,total_players,total_items,total_points

	Sql="Select * from raid_class"
	rs.open sql,conn,1,1
		if rs.eof or rs.bof then 
			Response.write "没有建立分类"
			exit sub
		end if
		Redim ArrClass(rs.recordcount-1,1)
		for i = 1 to rs.recordcount
			ArrClass(i-1,0)=rs("id")
			ArrClass(i-1,1)=rs("class_name")
			rs.movenext
		next
	rs.close
	
	dkpdata=dkpdata&"DKP_tables = {}" &vbCrlf
	for j = 0 to UBound(ArrClass)
		dkpdata=dkpdata&"DKP_tables["&j+1&"] = {" &vbCrlf

		sql="select * from player order by player_name"
		rs.open sql,conn,1,1
			membercount=rs.recordcount
			for i = 1 to rs.recordcount
				thisdkp=totaldkp(rs("id"),Arrclass(j,0))
				dkpdata=dkpdata&"	{ nick="""&rs("player_name")&""", class=DKPT_"&ProCN2EN(rs("player_profession"))&", current="&thisdkp&", spent=0.00 }," &vbCrlf
			rs.movenext
			next
		rs.close
		dkpdata=dkpdata&"};" &vbCrlf
		dkpdata=dkpdata&"DKP_tables["&j+1&"].title = """&Arrclass(j,1)&""";" &vbCrlf
		dkpdata=dkpdata&"DKP_tables["&j+1&"].url = ""见公会信息"";" &vbCrlf
		dkpdata=dkpdata&"DKP_tables["&j+1&"].members = "&membercount&";" &vbCrlf
	next
	dkpdata=dkpdata&"DKP_tables_count = "&UBound(ArrClass)+1 &vbCrlf

	call WriteFile("export/","dkp.lua.txt",dkpdata) 
end sub




'MerDKP 2.0+ DataFormat
Sub  export_MerDKP2()
	Dim ArrClass , membercount , ClassText
	dim dkpdata,total_players,total_items,total_points

	Sql="Select * from raid_class"
	rs.open sql,conn,1,1
		if rs.eof or rs.bof then 
			Response.write "没有建立分类"
			exit sub
		end if
		Redim ArrClass(rs.recordcount-1,1)
		for i = 1 to rs.recordcount
			ArrClass(i-1,0)=rs("id")
			ArrClass(i-1,1)=rs("class_name")
			ClassText=ClassText&""""&rs("class_name")&""""&","
			rs.movenext
		next
	rs.close
	dkpdata=dkpdata&"Mer_DKP_UPDATETIME = """&getRT150Time(today)&""";" &vbCrlf
	dkpdata=dkpdata&"MerDKP_Table = {};" &vbCrlf

	dkpdata=dkpdata&"" &vbCrlf

	for j = 0 to UBound(ArrClass)
	dkpdata=dkpdata&"MerDKP_Table["&j+1&"]  = {" &vbCrlf

		sql="select * from player  where player_lastraid > #"&DateADD("d",freezeday,today)&"#  order by player_name"
		rs.open sql,conn,1,1
			membercount=rs.recordcount
			for i = 1 to rs.recordcount
				thisdkp=totaldkp(rs("id"),Arrclass(j,0))
				dkpdata=dkpdata&"	{name="""&rs("player_name")&""",class="""&getHeXieProfessionName(rs("player_profession"))&""",dkp="&Round(thisdkp,2)&",online=1},"&vbCrlf
			rs.movenext
			next
		rs.close
		dkpdata=dkpdata&"};" &vbCrlf
		dkpdata=dkpdata&"MerDKP_Table["&j+1&"].title="""&ArrClass(j,1)&""";" &vbCrlf
		dkpdata=dkpdata&"MerDKP_Table["&j+1&"].whisper=""1"";" &vbCrlf
		dkpdata=dkpdata&"MerDKP_Table["&j+1&"].key="""&ArrClass(j,1)&""";" &vbCrlf
	next
	call WriteFile("export/","dkp_list.lua.txt",dkpdata) 
end sub


Function ProCN2EN(t)
	Select Case T
		Case "战士"
			ProCN2EN="warrior"
		Case "法师"
			ProCN2EN="mage"
		Case "牧师"
			ProCN2EN="priest"
		Case "圣骑士"
			ProCN2EN="paladin"
		Case "猎人"
			ProCN2EN="hunter"
		Case "德鲁伊"
			ProCN2EN="druid"
		Case "盗贼"
			ProCN2EN="rogue"
		Case "术士"
			ProCN2EN="warlock"
		Case "萨满祭司"
			ProCN2EN="shaman"
		Case else
			ProCN2EN="unknow"
		End Select
End Function
%>